﻿
function getDays(releaseDate) {
    var dateNow = new Date();
    var differenceInMilliseconds = releaseDate - dateNow;
    var millisecondsInADay = 86400000; // 24 * 60 * 60 * 1000;
    var days = (differenceInMilliseconds / millisecondsInADay) - 1;
    var roundedDays = Math.round(days);
    return roundedDays;
}
function getHours() {
    var timeNow = new Date();
    var hours = new Date();
    hours.setHours(24 - timeNow.getHours() - 1, 60 - timeNow.getMinutes() - 1, 60 - timeNow.getSeconds());
    if (timeNow.getMinutes() == 0 && timeNow.getSeconds() == 0) {
        hours.setHours(24 - timeNow.getHours() - 1);
    }
    if (timeNow.getSeconds() == 0) {
        hours.setMinutes(60 - timeNow.getMinutes());
    }
    return hours;
}

function startTimer() {
    setInterval('timerFunc()', 1000);
    timerFunc();
}

function timerFunc() {
    updateHMM6();
    updateBatman();
    updateAssassin();
    updateSWTOR();
}

function updateSWTOR() {
    var field = document.getElementById("swtor");
    var releaseDate = new Date();
    releaseDate.setMonth(11, 22);
    var days = getDays(releaseDate);
    var hours = getHours(releaseDate);
    var result = (days + " days " + hours.getHours() + ":" + hours.getMinutes() + ":" + hours.getSeconds());
    field.value = result;
}

function updateHMM6() {
    var field = document.getElementById("hmm6");
    var releaseDate = new Date();
    releaseDate.setMonth(9, 13);
    var days = getDays(releaseDate);
    var hours = getHours(releaseDate);
    var result = (days + " days " + hours.getHours() + ":" + hours.getMinutes() + ":" + hours.getSeconds());
    field.value = result;
}

function updateBatman() {
    var field = document.getElementById("batman");
    var releaseDate = new Date();
    releaseDate.setMonth(10, 1);
    var days = getDays(releaseDate);
    var hours = getHours(releaseDate);
    var result = (days + " days " + hours.getHours() + ":" + hours.getMinutes() + ":" + hours.getSeconds());
    field.value = result;
}

function updateAssassin() {
    var field = document.getElementById("assassin");
    var releaseDate = new Date();
    releaseDate.setMonth(10, 15);
    var days = getDays(releaseDate);
    var hours = getHours(releaseDate);
    var result = (days + " days " + hours.getHours() + ":" + hours.getMinutes() + ":" + hours.getSeconds());
    field.value = result;
}